<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
    <meta name="author" content="GeeksLabs">
    <meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
    <link rel="shortcut icon" href="img/favicon.png">
  </head>
  <body>
  <!-- 添加项目 -->
  <div class="modal-header">
                  <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                  <h4 class="modal-title">添加包裹</h4>
              </div>
              <div class="modal-body">
  <form role="form" id="inputForm">
    <input type="hidden" name="orderId" value="#(order.id)">
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">快递公司：</label>
                            <div class="col-sm-3">
                            	<select class="form-control" name="expressCode" id="expressCode">
                                    <option value="">--请选择--</option>
                                    <option value="SFEXPRESS">顺丰</option>
                                    <option value="YTO">圆通</option>
                                    <option value="ZTO">中通</option>
                                    <option value="STO">申通</option>
                                    <option value="HTKY">汇通快递</option>
                                    <option value="YUNDA">韵达快递</option>
                                    <option value="CHINAPOST">邮政包裹</option>
                                </select>
                            </div>
                            </div>
                      </div>
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">快递单号：</label>
                            <div class="col-sm-5">
                            	<input class="form-control" type="text" name="expressNumber" id="expressNumber">
                            </div>
                            </div>
                      </div>
                      
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">包裹重量：</label>
                            <div class="col-sm-5">
                            	<input class="form-control" type="text" name="weight" id="weight">
                            </div>
                            </div>
                      </div>
                      
                       <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">打包图片：</label>
                            <div class="col-sm-3" id="fileImage">
                            </div>
                            <div class="col-sm-3">
                                <a href="javascript:;" id="filePicker" class="btn btn-primary">选择文件</a>
                            </div>
                      </div>
                       </div>
                      
                       <div class="form-group" id="productDiv">
                       		<table class="table table-bordered">
                                <thead>
                                    <tr>
                                    	<th>选择</th>
                                        <th>商品条码</th>
                                        <th>商品图片</th>
						                <th>商品名称</th>
						                <th>订单数量</th>
						                <th>包裹数量</th>
                                     </tr>
                                 </thead>
                                 <tbody>
                                     #for(orderItem : order.orderItems)
				                    <tr>
				                    	<td><input type="checkbox" name="productId" value="#(orderItem.productId)"></td>
					                    <td>#(orderItem.sn)</td>
					                    <td><img src="#(imageUrl(orderItem.image))" height="50"/></td>
					                    <td>#(orderItem.name)</td>
					                    <td>#(orderItem.quantity)</td>
					                    <td><input class="form-control" type="text" name="quantity" value=""></td>
				                    </tr>
				                    #end
                                 </tbody>
                             </table>
                       
                       
                       </div>
                      
                      
                      
                      
                      <div class="row">
                      <label class="col-sm-3 control-label">&nbsp;</label>
                      <div class="col-sm-3">
                      <button type="button" class="btn btn-primary" style="margin-top: 20px;" id="saveRole">确定</button>
                      </div>
                      </div>
                  </form>
  
  </div>
  </body>
</html>

<script type="text/javascript">

function fileUploadCall(fromType,url){
	var html='<img alt="" src="'+url+'" height="110"><input type="hidden" name="photo" value="'+url+'"/>';
	$("#fileImage").html(html);
}


var $filePicker = $("#filePicker");



$filePicker.uploader();


$("#saveRole").on("click",function(){
	if(isEmpty($("#expressCode").val())){
		alert("请输入快递公司!");
		return false;
	}  
	
	if(isEmpty($("#expressNumber").val())){
		alert("请输入快递单号!");
		return false;
	}  
	
	var checkproduct = $("#productDiv").find("input[name='productId']:checked");
	if(checkproduct.length<1){
		alert("请选择商品");
		return false;
	}
	var checkQuantity=true;
	var checkQuantityReg=true;
	$.each(checkproduct,function(index,item){
		var quantity = $(item).closest("tr").find("input[name='quantity']").val();
		if(isEmpty(quantity)){
			alert("请输入包裹数量");
            checkQuantity=false;
			return;
		}
		var quantityReg = /^\+?[1-9][0-9]*$/;  ;
		if(!quantityReg.test(quantity)){
			alert("请输入正确的包裹数量");
            checkQuantityReg=false;
			return;
		}
		
	});
	if(!checkQuantity || !checkQuantityReg){
        return false;
    }
	
	$.ajax({
        url: "updatePackProduct",
        type: "POST",
        data: $("#inputForm").serialize(),
        dataType: "json",
        cache: false,
        success: function(response) {
        	if (response.type == "success") {
        		alert("操作成功");
        		location.reload();
            }else{
                swal({title:'', text:response.msg,icon: 'error'});
            }
        }
    });
	
});
</script>